package com.manxi.mapper;

import com.github.pagehelper.Page;
import com.manxi.annotation.AutoFill;
import com.manxi.dto.DishPageQueryDTO;
import com.manxi.entity.Dish;
import com.manxi.entity.DishFlavor;
import com.manxi.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishFlavorMapper {

    /**
     * 批量插入口味数据
     *
     * @param flavors
     */
    @Insert("<script>" +
            "insert into dish_flavor (dish_id, name, value) values " +
            "<foreach collection='flavors' item='df' separator=','>" +
            "(#{df.dishId},#{df.name},#{df.value})" +
            "</foreach> " +
            "</script>")
    void insertBatch(List<DishFlavor> flavors);


    /**
     * 根据菜品id删除相关联的口味表
     * @param dish_id
     */
    @Delete("delete from dish_flavor where dish_id = #{dish_id}")
    void deleteByDishId(Long dish_id);

    /**
     * 根据菜品id查询菜品口味
     * @param dish_id
     * @return
     */
    @Select("select * from dish_flavor where dish_id = #{dish_id}")
    List<DishFlavor> getByDishId(Long dish_id);
}
